<?php
/**
 * @author barthez|deeFlow
 */
namespace Engine\Classes;
class Collector {
    
    private $_allowed = array('news','articles','problems','rss');
    private $_entities = array();
    private $_view = array();
    
    public function __construct($view) {
        $this->_view = $view;
    }

    public function _console($command) {
        $data = \explode(' ', $command);
        $action = $data[0];
        $params = $data[1];
        
        if(\in_array($action, $this->_allowed)) {
            $params = \explode(';', $params);
            $this->_entities[$action] = $params;
        }
    }
    
    public function _render() {
        
        if(array_key_exists('rss',$this->_entities)) {      
            $rssManager = new \Managers\Rss();
            $this->_view->habr = $rssManager->getRss(
                $this->_entities['rss'][0], 
                $this->_entities['rss'][1]
            );
            
        }
        
        if(array_key_exists('articles',$this->_entities)) {          
            $articlesManager = new \Managers\Article();
            if($this->_entities['articles'][0] == 'getall') {
                $this->_view->articlesList = $articlesManager->getAllArticles();
            }
        }
        
        if(array_key_exists('news',$this->_entities)) {          
            $newsManager = new \Managers\News();
            $this->view->newsList = $newsManager->getAllNews();
        }

        return $this->_view;
    }

}


?>
